﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Text;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;

namespace wdss.WebServices
{
    /// <summary>
    /// Summary description for DetectXSSAttemptService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class DetectXSSAttemptService : System.Web.Services.WebService
    {

        public DetectXSSAttemptService()
        {

            //Uncomment the following line if using designed components 
            //InitializeComponent(); 
        }

        [WebMethod]
        public bool IsXSSInjection(string input)
        {
            input = input.ToLower();
            if (input.Contains("<applet") ||
                input.Contains("<body") ||
                input.Contains("<embed") ||
                input.Contains("<frame") ||
                input.Contains("<script") ||
                input.Contains("<frameset") ||
                input.Contains("<html") ||
                input.Contains("<iframe") ||
                input.Contains("<img") ||
                input.Contains("<style") ||
                input.Contains("<layer") ||
                input.Contains("<link") ||
                input.Contains("<ilayer") ||
                input.Contains("<meta") ||
                input.Contains("<object") ||
                input.Contains("<src") ||
                input.Contains("<lowsrc") ||
                input.Contains("<href"))
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        [WebMethod]
        public String EncodeString(string input)
        {
            return Server.HtmlEncode(input);
        }

        [WebMethod]
        public StringBuilder EncodeURL(string input)
        {
            StringBuilder output = new StringBuilder(HttpUtility.UrlEncode(input));
            return output;
        }
    }
}
